/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package carstore.ui.services;

import carstore.ui.interfaces.CarstoreClient;
import carstore.ui.interfaces.OrderInfoClient;
import carstore.ui.interfaces.UserClient;
import carstore.ui.models.Car;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import carstore.ui.models.User;
import carstore.ui.models.OrderInfo;
import carstore.ui.models.OrderInfoExt;
import carstore.ui.models.Carstore;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
/**
 *
 * @author wuhao
 */
@Service
public class MainService{
	@Autowired
	private UserClient userClient;
	
	@Autowired
	private CarstoreClient carstoreClient;
	
	@Autowired
	private OrderInfoClient orderinfoClient;
	
	public String getBookUrl(){
		System.out.println("get booking url");
		return "";
		//return orderinfoClient.getBookUrl();
	}
	
	//@HystrixCommand(fallbackMethod = "fallbackSearchAll")
	public List<User> searchAllUsers() {
		System.out.println("search all users");
		return userClient.getAllUsers();
	}
	
	//@HystrixCommand(fallbackMethod = "fallbackSearchAll")
	public List<OrderInfo> searchAllOrders(){
		System.out.println("search all orders");
		return orderinfoClient.getAllOrders();
	}

	public List<OrderInfoExt> getOrdersbyUserId(int UserId){
		System.out.println("search orders by userid");
		return orderinfoClient.getOrdersbyUserId(UserId);
	}
	
	//@HystrixCommand(fallbackMethod = "fallbackSearchAll")
	public List<Carstore> searchAllCarStores(){
		System.out.println("search all car stores");
		return carstoreClient.getAllCarstores();
	}
	
	public List<Car> getCarsbyUserId(int UserId) {
		//System.out.println("search cars of "+UserId);
	    //System.out.println("MainService.getCarsbyUserId");
		List<Car> Carlist=userClient.getCarsbyUserId(UserId);
		return Carlist;
	}

	public List<User> getUsersbyUserId(int UserId) {
		System.out.println("get users of "+UserId);
		List<User> Userlist=userClient.getUserbyUserId(UserId);
		System.out.println("get users completed!");
		return Userlist;
	}

	public void setNewOrderInfo(BigInteger orderId, String orderTime, int storeId, int carID, int userId, String orderStatus) {
		orderinfoClient.setNewOrderInfo(orderId,orderTime,storeId,carID,userId,orderStatus);
	}

	public void setPayOrderStatus(BigInteger orderId) {
		orderinfoClient.setPayOrderStatus(orderId);
	}

	public void setCarSelectStatus(Integer UserId,Integer CarId){
		//System.out.println("ui.MainService.setCarSelectStatus");
		userClient.setCarSelectStatus(UserId,CarId);
		}
}
